<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 需要启动服务测试 例如anywhere -->
    <input type="text" name="" id="text">设置key
    <input type="text" name="" id="text2">value
    <input type="button" id='btn' value="提交">
    <script>
        btn.addEventListener('click', function () {
            var d = new Date();
            d.setTime(d.getTime() + (1 * 24 * 60 * 60 * 1000));
            var expires = "expires=" + d.toUTCString();
            document.cookie = text.value + "=" + text2.value + ";" + expires;
        })
    </script>

</body>

</html>